package com.yanqu.road.dao.impl.servercenter;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.servercenter.AppKeyInfo;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * appKey信息
 */
public class AppKeyDaoImpl extends TempDao {

	public Map<Long, AppKeyInfo> getAppKeyInfoMap() {
		ResultSet rs = null;
		CallableStatement call = null;
		String sql = "select * from t_s_app_key";
		Map<Long, AppKeyInfo> dataMap = new ConcurrentHashMap<>();
		try {
			getDb().setConnName(DbNameStrategy.getServerDb());
			call = getDb().getConnection().prepareCall(sql);
			rs = call.executeQuery();
			while (rs.next()) {
				AppKeyInfo data = new AppKeyInfo();
				data.setServerId(rs.getLong("serverId"));
				data.setPlatformBaseUrl(rs.getString("platformBaseUrl"));
				data.setAndroidAppId(rs.getString("androidAppId"));
				data.setAndroidAppKey(rs.getString("androidAppKey"));
				data.setAndroidAppSecret(rs.getString("androidAppSecret"));
				data.setPlatformChannelId(rs.getString("platformChannelId"));
				dataMap.put(data.getServerId(), data);
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		} finally {
			getDb().closeConnection(call, rs);
		}

		return dataMap;
	}
}
